package jflowmap.export;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractExporter implements Exporter {
	private final List<Runnable> finishedCallbacks = new ArrayList<Runnable>();
	private final List<Runnable> startingCallbacks = new ArrayList<Runnable>();
	
	@Override
	public void onExportFinished(Runnable callback) {
		finishedCallbacks.add(callback);
	}
	
	@Override
	public void onExportStarted(Runnable callback) {
		startingCallbacks.add(callback);
	}
	
	protected final void callFinished() {
		for (Runnable runnable: finishedCallbacks) {
			runnable.run();
		}
		finishedCallbacks.clear();
	}
	
	protected final void callStarted() {
		for (Runnable runnable: startingCallbacks) {
			runnable.run();
		}
		startingCallbacks.clear();
	}	
}
